/******************************************************************************
This .do file produces the main results reported in Figures OB3 & OB4. 
The figures were produced in R using estimated saved from these analyses. 
******************************************************************************/

clear
use "ess_cleaned_whole.dta"
set more off

*Restrict to citizens
keep if citizen == 1

/*********************************
Weights
*********************************/

gen anweight = pspwght*pweight
label var anweight "Analysis Weight"
*Note: svyset is not used because mixed does not work with svy: in this version of Stata. 

/*********************************
Labelling
*********************************/

label var self_te "Self Transcendence vs. Self-Enhancement"
label var cons_open1 "Conservation vs. Openness"
label var age "Age"
label var gender "Gender"
label def gend 1 "Female" 0 "Male"
label values gender gend

recode born_when (1=1 "Born in Country") (2 3 4 = 2 "Came to Country <20 Yrs Ago") (5 = 3 "Came to Country 20+ Yrs Ago"), gen(born_when1)
label var born_when1 "Born in Country?"

recode minority (0=1 "Minority Group") (1=0 "Non-Minority"), gen(minority1)
label var minority1 "Member of Minority?"

recode edulvla (55=.)
label var edulvla "Own Education"
label def ed 0 "Other Ed Level"  1 "< Lower Secondary" 2 "Lower Secondary" 3 "Upper Secondary" 4 "Post-Secondary, Non-Tertiary" 5 "Tertiary Education"
label values edulvla ed

recode edulvlfa (55=.)
label var edulvlfa "Father's Education"
label val edulvlfa ed

recode union (1 = 0 "Never a Union Member") (2 3 = 1 "Currently/Previously in Union"), gen(union1)
label var union1 "Union Membership"

label var socialtrust "Interpersonal Trust"
label var sclmeet "Freq of Social Interactions"
label var religiosity "Religiosity"
label var yrlvdae "Residential Stability"

label def dom 1 "Big City" 2 "Suburbs" 3 "Small City" 4 "Country Village" 5 "Countryside" 
label values domicil dom

label var post_soviet "Socialist Country?"
label def pos 1 "Socialist Country" 0 "Non-Socialist Country"
label values post_soviet pos

label var demyrs_01 "Years of Democracy"
label var ethnic_01 "Ethnic Heterogeneity"

**correlation between different versions of the conservation scale
pwcorr cons_open cons_open1

/*********************************
Rescaling Continuous Variables to 0-1 Scale
*********************************/

foreach var in support_others vote_elections obey opinions volunteer beactive self_te cons_open1 age socialtrust sclmeet religiosity yrlvdae {
	summ `var'
	replace `var' = (`var' - r(min))/(r(max)-r(min))
}


/*********************************
Models, Table, Saved Results
*********************************/

foreach var in vote_elections obey support_others opinions volunteer beactive  {
	local m2 " age i.gender i.minority1 i.union1 i.edulvla ib1.edulvlfa i.born_when1 i.post_soviet demyrs_01 ethnic_01"
	local m3 " age i.gender i.minority1 i.union1 i.edulvla ib1.edulvlfa i.born_when1 socialtrust sclmeet religiosity yrlvdae i.post_soviet demyrs_01 ethnic_01 "
	eststo clear
	eststo: mixed `var' self_te cons_open1 [pweight=anweight] || country: self_te cons_open1,  stddev
		parmest, label format(estimate min95 max95 p) list(parm label estimate min95 max95 p) saving(`var'1_red.dta, replace)
	eststo: mixed `var' self_te cons_open1 `m2' [pweight=anweight] || country: self_te cons_open1,  stddev
		parmest, label format(estimate min95 max95 p) list(parm label estimate min95 max95 p) saving(`var'2_red.dta, replace)
	eststo: mixed `var' self_te cons_open1 `m3' [pweight=anweight] || country: self_te cons_open1,  stddev
		parmest, label format(estimate min95 max95 p) list(parm label estimate min95 max95 p) saving(`var'3_red.dta, replace)
	esttab using `var'_red.rtf, replace label se b(2) aic bic onecell transform(ln*: exp(@) exp(@)) ///
		addnote("Models use survey weights. Value orientation slopes are allowed to vary across countries. All continuous variables are scaled to range from 0-1.") ///
		mtitles("Model 1" "Model 2" "Model 3") ///
		title("{\b Table X}: Value Orientations (Reduced Form  Conservation vs. Openness) and `var'") ///
	order(self_te cons_open1 age 0.gender 1.gender 0.minority1 1.minority1 0.union1 1.union1 1.edulvla 2.edulvla 3.edulvla 4.edulvla 5.edulvla ///
		1.edulvlfa 2.edulvlfa 3.edulvlfa 4.edulvlfa 5.edulvlfa 0.edulvlfa 1.born_when1 2.born_when1 3.born_when1 socialtrust sclmeet religiosity yrlvdae 0.post_soviet 1.post_sovet demyrs_01 ethnic_01)
	}



	
	
	
	
	
	
	
	
	


